﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Karasoft.Web.UI
{
    /// <summary>
    /// Summary description for ExtensionsClass
    /// </summary>
    public static class Extensions
    {
        public static T FindControlRecursive<T>(this Control parentControl, string id) where T : Control
        {
            T ctrl = default(T);

            if ((parentControl is T) && (parentControl.ID == id))
                return (T)parentControl;

            foreach (Control c in parentControl.Controls)
            {
                ctrl = FindControlRecursive<T>(c, id);

                if (ctrl != null)
                    break;
            }
            return ctrl;
        }

        public static int? ToIntN(this String text)
        {
            return string.IsNullOrEmpty(text) == true ? (int?)null : int.Parse(text);
        }
        public static int ToInt(this String text)
        {
            return string.IsNullOrEmpty(text) == true ? 0 : int.Parse(text);
        }
    }
}
